Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 2 - AppleScript Language Reference
Chapter 6 - Expressions / AppleScript Properties


Text Item Delimiters

The Text Item Delimiters property consists of a list of strings used as delimiters by AppleScript when it coerces lists to strings or gets text items from strings.

You can get and set the current value of AppleScript's Text Item Delimiters. Normally, AppleScript doesn't use any delimiters. For example, the script

{"bread", "milk", "butter", 10.45} as string
returns this result if AppleScript's text delimiters have not been
explicitly changed:

"breadmilkbutter10.45"
For printing or display purposes, it is usually preferable to set the text delimiters to something that's easier to read. For example, the script

set AppleScript's text item delimiters to {", "}
{"bread", "milk", "butter", 10.45} as string
returns this result:

"bread, milk, butter, 10.45" 
The Text Item Delimiters property also allows you to extract individual names from a pathname. For example, the script

set AppleScript's text item delimiters to {":"}
get last text item of "Hard Disk:CD Contents:Release Notes"
returns the result "Release Notes".

Once you change the Text Items Delimiters property, it remains set until you restart your computer. Currently, AppleScript uses only the first delimiter in the list.

You may want to use an error handler to reset the Text Item Delimiters property to its former value if an error occurs:

set savedTextItemDelimiters to AppleScript's text item¬
   delimiters
try
   set AppleScript's text item delimiters to {"**"}
   --rest of script...

   --finally, reset the text item delimiters:
   set AppleScript's text item delimiters to¬
      savedTextItemDelimiters
on error m number n from f to t partial result p
   --also reset text item delimiters in case of an error:
   set AppleScript's text item delimiters to ¬
      savedTextItemDelimiters
   --and resignal the error:
   error m number n from f to t partial result p
end try 

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996